package com.gh.rabbitmq.two;

import com.gh.rabbitmq.utils.RabbitmqUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * @Author Eric
 * @Date 2021/7/17 17:02
 * @Version 1.0
 * 这是一个工作线程
 */
public class Work01 {
    //队列的名称
    public static final String QUEUE_NAME = "hello";

    //接收消息
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitmqUtils.getChannel();
        //声明接收消息
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("接收到的消息"+new String(message.getBody()));
        };
        //取消消息时的回调
        CancelCallback cancelCallback = consumerTag -> {
            System.out.println("消费消息被中断了");
        };
        //消息的接收
        System.out.println("C2等待接收消息....");
        channel.basicConsume(QUEUE_NAME, true, deliverCallback, cancelCallback);
    }
}
